<template>
	<view class="tui-userinfo-box">
		<tui-list-cell padding="0" :arrow="true" unlined @click="href(3)">
			<view class="tui-list-cell" v-if="userInfo.mobile">
				<view>已绑定手机号</view>
				<view class="tui-content">{{userInfo.mobile}}</view>
			</view>
			<view class="tui-list-cell" v-else>
				<view>绑定手机号</view>
			               <view class="tui-content"></view>
			            </view>
		</tui-list-cell>
		<tui-list-cell padding="0" :lineLeft="false" :arrow="true" @click="href(2)">
			<view class="tui-list-cell">
				重设密码
			</view>
		</tui-list-cell>
		<tui-list-cell padding="0" :lineLeft="false" :arrow="true" @click="logout">
			<view class="tui-list-cell">
				退出登录
			</view>
		</tui-list-cell>
	</view>
</template>

<script>
	import tuiListCell from '@/components/tui/tui-list-cell';
	import tuiButton from "@/components/tui/tui-button"
	export default {
		components: {
			tuiListCell,
			tuiButton
		},
		data() {
			return {
				userInfo:{nickname:'',birthday:'',sex:'',headpic:''},
			}
		},
		onLoad() {
			
			this.getUserInfo()
			
			
		},
		onShow() {
			this.$U.checkLogin()
		},
		methods: {
			//退出登录
			logout() {
				let token = uni.getStorageSync('token');
				let come_from = this.$come_from
				let data = {token:token,from:come_from}
				
				console.log(token)
				if(token){
					this.$H.post('sapi/auth/logout',data).then(res => {
						if(res.data.token == ''){
							uni.removeStorageSync('token');
							uni.removeStorageSync('my');
							uni.removeStorageSync('config')
							this.userinfo = []
							// #ifdef MP-WEIXIN || APP-PLUS
							uni.navigateTo({
								url: '/pages/login/login'
							})
							// #endif
							// #ifdef H5
								var domine = window.location.href.split("?code")[0]
								console.log('url:')+domine
							     window.location.href = domine+'#/pages/login/login'
							// #endif
						}	
								
						})
					
				}
				
			},
			bindTel(){
				this.$U.href("./bindTel")
			},
			getUserInfo:function(){
				let that = this
				that.$H.post('sapi/uinfo/info',that.form).then(res => {
					if(res.status == 200 && res.data){
						console.log('res.data:'+JSON.stringify(res.data))
						that.userInfo = res.data;
					}else if(res.status == 400){
						setTimeout(() => {	
						}, 2000);
						uni.showToast({
							title:res.msg,
							icon:"none"
						})
					}
						
						
							
					})
				
			},
			href(page) {
				
				let url = "";
				switch (page) {
					case 1:
						url = "./userInfo/userInfo"
						break;
					case 2:
						url = "/pages/login/forgetPwd"
						break;
					case 3:
						url = "/pages/user/account/bindTel"
						break;
					
					default:
						break;
				}
				uni.navigateTo({
					url: url
				})
			}
		}
	}
</script>

<style>
	.tui-userinfo-box {
		margin: 20rpx 0;
		color: #333;
	}

	.tui-list-cell {
		width: 100%;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 24rpx 60rpx 24rpx 30rpx;
		box-sizing: border-box;
		font-size: 30rpx;
	}

	.tui-pr30 {
		padding-right: 30rpx;
	}

	.avatar {
		width: 100rpx;
		height: 100rpx;
		display: block;
		border-radius: 50%;
	}

	.tui-content {
		font-size: 26rpx;
		color: #666;
	}
</style>
